/*
 ********************************************************************************
 * @FileName  : usb_main.h
 * @CreateDate: 2021-5-17
 * @Author    : GaoQiu
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 ********************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */

#ifndef USB_MAIN_H_
#define USB_MAIN_H_

#include "usb_def.h"
#include "usb_port.h"

#define USB_REQ_TYPE_POS     0
#define USB_REQ_POS          1
#define USB_VALUE_POS        2
#define USB_INDEX_POS        4
#define USB_LEN_POS          6

typedef struct{
	uint8_t  reqType;
	uint8_t  req;
	uint16_t value;
	uint16_t index;
	uint16_t length;
}UsbReq_t;

typedef struct{
	uint8_t dataToggle; /*!< DATA0/DATA1 */
	bool_t  status;     /*!< ACK/NACK/STALL/NYET */
}EdpCb_t;

typedef struct{
	uint8_t   reqBuf[USB_LEN_STD_REQ];  /*!< use for endpoint SETUP. */
	EdpCb_t   edp[USB_EDP_NUM];
	uint8_t   *pTxBuf;                  /*!< use for control endpoint send data. */
	uint16_t  len;                      /*!< the length of tx. */
	uint8_t   configId;
	uint8_t   intfAltSetting;
	bool_t    suspendEn;
}UsbCb_t;

extern UsbCb_t  usbCb;

#define USB_DATA_DIR(reqType)   (((reqType) >> 7) & 0x01)
#define USB_REQ_TYPE(reqType)   (((reqType) >> 5) & 0x03)
#define USB_RECIPIENT(reqType)  (((reqType) >> 0) & 0x1f)


void USB_Reset(void);


#endif /* USB_MAIN_H_ */
